package com.xywy.wjk;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeSet;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.xywy.R;
import com.xywy.common.BaseActivity;
import com.xywy.common.widget.TitleBar2;

public class WeightNounExplainActivity extends BaseActivity implements
		OnClickListener {

	private TitleBar2 titleBar;
	private TextView tvBack;
	private TextView tvGo;
	private TextView tvTitle;
	private TextView weight_noun_explain_content;
	private ListView lv_weight_health_standard;
	private static HashMap HealthMaps[] = new HashMap[9];
	private static HashMap<String, String> BmihealthStandard;
	private static HashMap<String, String> TzLMap;
	private static HashMap<String, String> StnlMap;
	private static HashMap<String, String> JrlMap;
	private static HashMap<String, String> NzzfMap;
	private static HashMap<String, String> JcdxMap;
	private static HashMap<String, String> BelowSkinFatMap;
	private static HashMap<String, String> BoneWeightMap;
	private static HashMap<String, String> ShlMap;
	// 初始化健康标准
	static {
		/**
		 * BMI
		 */
		BmihealthStandard = new HashMap<String, String>();
		BmihealthStandard.put("偏低", "<18.5");
		BmihealthStandard.put("标准", "18.5~24.0");
		BmihealthStandard.put("超高", ">24.0");
		/**
		 * 体脂率
		 */
		TzLMap = new HashMap<String, String>();
		TzLMap.put("偏低", "<13.0");
		TzLMap.put("标准", "13.0~21.0");
		TzLMap.put("超高", ">21.0");
		/**
		 * 水含量标准
		 */
		ShlMap = new HashMap<String, String>();
		ShlMap.put("偏低", "<53.6");
		ShlMap.put("标准", "53.6~57.0");
		ShlMap.put("偏高", ">57.0");
		/**
		 * 骨骼重量
		 */
		BoneWeightMap = new HashMap<String, String>();
		BoneWeightMap.put("偏低", "<2.4");
		BoneWeightMap.put("标准", "2.4~2.6");
		BoneWeightMap.put("偏高", ">2.6");
		/**
		 * 皮下脂肪
		 */
		BelowSkinFatMap = new HashMap<String, String>();
		BelowSkinFatMap.put("偏低", "<8.6");
		BelowSkinFatMap.put("标准", "8.6~16.7");
		BelowSkinFatMap.put("偏高", ">16.7");
		/**
		 * 基础代谢
		 */
		JcdxMap = new HashMap<String, String>();
		JcdxMap.put("未达标", "<1510");
		JcdxMap.put("达标", ">1510");
		/**
		 * 内脏脂肪
		 */
		NzzfMap = new HashMap<String, String>();
		NzzfMap.put("偏低", "<9.0");
		NzzfMap.put("标准", "9.0~15.0");
		NzzfMap.put("偏高", ">15.0");
		/**
		 * 肌肉率
		 */
		JrlMap = new HashMap<String, String>();
		JrlMap.put("偏低", "<49.4");
		JrlMap.put("标准", "49.4~59.4");
		JrlMap.put("偏高", ">59.4");
		/**
		 * 身体年龄
		 */
		StnlMap = new HashMap<String, String>();
		StnlMap.put("低于实际年龄", "");
		StnlMap.put("高于实际年龄", "");

		HealthMaps[0] = BmihealthStandard;
		HealthMaps[1] = StnlMap;
		HealthMaps[2] = TzLMap;
		HealthMaps[3] = JrlMap;
		HealthMaps[4] = ShlMap;
		HealthMaps[5] = JcdxMap;
		HealthMaps[6] = BoneWeightMap;
		HealthMaps[7] = BelowSkinFatMap;
		HealthMaps[8] = NzzfMap;

	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_weight_noun_explain);
		preInit();
		initView();
		loadData();
		this.setListener();
	}

	@Override
	public void initView() {
		// TODO Auto-generated method stub
		titleBar = (TitleBar2) findViewById(R.id.wjk_noun_explain_title_bar);
		tvTitle = titleBar.getTitle();
		tvBack = titleBar.getTvBack();
		tvGo = titleBar.getGo();
		weight_noun_explain_content = (TextView) findViewById(R.id.weight_noun_explain_content);

		lv_weight_health_standard = (ListView) findViewById(R.id.lv_weight_health_standard);

	}

	private void setListener() {
		// TODO Auto-generated method stub
		titleBar.onClickBack(this);
		tvBack.setOnClickListener(this);
	}

	@Override
	public void preInit() {
		// TODO Auto-generated method stub

	}

	@Override
	public void loadData() {
		// TODO Auto-generated method stub
		Intent intent = this.getIntent();
		// tvTitle.setText(getString(R.string.main_wjk_add_bmi));
		tvTitle.setText(this.getIntent().getStringExtra("ItemName"));
		tvBack.setText(getString(R.string.back));
		tvGo.setText("");
		String[] NounExpain = {
				"BMI是目前国际上常用的衡量人体胖瘦程度以及是否健康的一个标准。",
				"身体年龄是以基础代谢为基础，综合体重，身体脂肪率，肌肉率等数值，换算所得出的数值。所以身体年龄是一个高于或低于实际年龄的综合判断身体状况的标准。",
				"脂肪率是指人体内脂肪重量在人体总体重中所占的比例，又称体脂百分数，它反映人体内脂肪含量的多少。",
				"肌肉率是根据人体肌肉总量和人体体重、身高等相结合得到的人体的一个比例值，这个值的范围决定一个人的身体健康状况以及力量的多少。",
				"水含量指的是在人体内所蕴含的水分比。",
				"基础代谢率（BMR）是指人体在清醒而又极端安静的状态下，不受肌肉活动、环境温度、食物及精神紧张等影响时的能量代谢率。高代谢率有助于减少人体脂肪，每天适量运动有助于提高身体的基础代谢率。",
				"骨骼重量指的是单位体积内，骨组织[骨矿物质（钙、磷等）和骨基质（骨胶原、蛋白质、无机盐等等）]含量",
				"皮下脂肪是判断人体的肥瘦情况，评价人身组成的比例一种方式，其主要反映的是储存于皮下脂肪组织的比例。",
				"内脏脂肪是人体脂肪中的一种，与皮下脂肪不同，它围绕着人的脏器，主要存在于腹腔内。",
				 };
		int i = this.getIntent().getIntExtra("position", 0);
		if (i == 0) {
			findViewById(R.id.ll_weight_computational_formula).setVisibility(
					View.VISIBLE);
		}
		weight_noun_explain_content.setText(NounExpain[i]);
		HealthStanderAdapter adapter = new HealthStanderAdapter(HealthMaps[i],
				this);
		lv_weight_health_standard.setAdapter(adapter);
		// lv_weight_health_standard.setAdapter(new SimpleAdapter(this, data,
		// R.layout.lv_weight_health_standard_item, , to));

	}

	@Override
	public void onClick(View view) {
		// TODO Auto-generated method stub
		switch (view.getId()) {
		case R.id.tv_title_back:
			back();
			break;

		default:
			break;
		}

	}

	private void back() {
		// TODO Auto-generated method stub
		// Intent intent = new Intent(this, WjkDetailActivity.class);
		// startActivity(intent);
		this.finish();
	}

	class HealthStanderAdapter extends BaseAdapter {
		HashMap<String, String> mValues;
		private Context mContext;
		List<Entry<String, String>> set = new ArrayList<Map.Entry<String, String>>();

		public HealthStanderAdapter(HashMap<String, String> mValues,
				Context mContext) {
			super();
			this.mValues = mValues;
			this.mContext = mContext;
			Set<Entry<String, String>> temp = (Set<Entry<String, String>>) mValues
					.entrySet();
			set.addAll(temp);
			if (mValues != null) {
			}
		}

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return mValues.size();
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup arg2) {
			// TODO Auto-generated method stub
			ViewHolder holder = null;
			Entry<String, String> entry = set.get(position);
			if (convertView == null) {
				holder = new ViewHolder();
				convertView = View.inflate(mContext,
						R.layout.lv_weight_health_standard_item, null);
				holder.keyTv = (TextView) convertView
						.findViewById(R.id.health_status);
				holder.valueTv = (TextView) convertView
						.findViewById(R.id.health_values);
				convertView.setTag(holder);
			} else {
				holder = (ViewHolder) convertView.getTag();
			}
			holder.keyTv.setText(entry.getKey());
			holder.valueTv.setText(entry.getValue());
			return convertView;
		}

		class ViewHolder {
			public TextView keyTv;
			public TextView valueTv;
		}
	}

}
